const sign = require('./sign')
const baseUrl = 'http://www.shopping.com/api'
const getData = (url,method,data,callBack)=>{
    // 生成时间戳
    let timestamp = Math.ceil((new Date()).getTime()/1000);
    data.timestamp = timestamp;
    // 生成签名
    let new_sign = sign(data)
    data.sign = new_sign
    return new Promise(function(resolve,reject){
        wx.request({
          url: baseUrl+url,
          method:method,
          data:data,
          header:{
              'Authorization':'bearer'+wx.getStorageSync('token')
          },
          success:res=>{
              resolve(res.data)
          },
          fail:err=>{
              reject(err)
              wx.showToast({
                title: '请求失败'
              })
          },
          complete:()=>{
              callBack && callBack()
          }
        })
    })
}

module.exports={
    getData:getData
}